
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%@page import="com.tss.util.*"%>
<%@page import="com.jedi.*"%>
<%@page import="com.store.*"%>
<%@page import="java.util.*"%>
<%@page import="java.text.*"%>
<%@include file="../global_var.jsp"%>
<%@include file="../check_login.jsp"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
User just_user = (User)session.getAttribute("LoginUser");
String power_enable_id = "10811";
if (!just_user.hasPower(power_enable_id)) {
	out.println(strNoPowerInfo); 
	return;
}

User user = (User)session.getAttribute("LoginUser");
String id = ParamUtils.getParameter(request,"id","");
String cmd = ParamUtils.getParameter(request,"cmd","");
String author_id   = "";
String author_name = "";
if (user != null && !user.getId().trim().equals("")) {
	author_id = user.getId();
	author_name = user.getUserName();
}

String strErr = "";
DownCate cate = null;
DownCateMgr cateMgr = new DownCateMgr();

int is_leaf = 0;
String parent_id = "";
String parent_name = "";

if (id != null && !id.trim().equals("")) {
	cate = cateMgr.get(id);
	if (cate != null && !cate.getId().equals("")) {
		if (cate.isLeaf()) 
			strErr = "这个分类已是子类，禁止添加子类!";
		else {
			parent_name = cate.getCategoryName();
			is_leaf = 1;
			parent_id = id;
		}
	}
	else {
		strErr = "父类信息不存在!";
	}
}

String category_name = ParamUtils.getParameter(request,"category_name","");
String category_desc = ParamUtils.getParameter(request,"category_desc","");
String order_id = ParamUtils.getParameter(request,"order_id","1");


if (cmd.trim().equals("insert") && strErr.trim().equals("")) {
	if (strErr.trim().equals("") && category_name.trim().equals("")) {
		strErr = "分类名称不能为空!";
	}
	if (strErr.trim().equals("")) {
		try {
			Integer.parseInt(order_id);
		}
		catch(Exception ex) {
			strErr = "分类顺序号必须为整数!";
		}
	}
	if (strErr.trim().equals("") && category_desc.length() > 100) {
		strErr = "分类描述不能超过100个字符!";
	}

	if (strErr.trim().equals("")) {
		DownCate item = new DownCate();
		item.setCategoryName(category_name);
		if (is_leaf == 1) {
			item.setLeaf();
			item.setParentId(parent_id);
		}
		item.setOrderId(Integer.parseInt(order_id));
		item.setCategoryDesc(category_desc);
		
		item.insert();
		if (item.hasErr()) strErr = item.getErrHtml();
	}
}
%>
<html>
<head>
   <base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
<link href="style/main.css" rel="stylesheet" type="text/css">
<script language="javascript" src="js/common.js"></script>
<script language="javascript">
function chk_submit() {
	var oForm = document.operatorForm;
	if (oForm.category_name.value == "") {
		alert("分类名称不能为空!");
		oForm.category_name.focus();
		return false;
	}
	if (oForm.order_id.value == "") {
		alert("顺序号不能为空!");
		oForm.order_id.focus();
		return false;
	}
	oForm.cmd.value = "insert";
	return true;
}
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td >
    <form name="operatorForm" method="post" onsubmit="return chk_submit();">
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td height="31" valign="top" background="images/title_bk_01.gif" style="padding-left:10px;padding-top:6px;">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="50%" style="color:#FFFFFF;font-size:13px;">
                  <b>知识库</b> -&gt; 
                  <b>添加文章分类</b>
                </td>
                <td width="50%" align="right" style="padding-right:10px;">&nbsp;
                  <span onclick="right_menu_clk('know_article_cate_list.jsp');" style="cursor:hand;color:#FFFFFF;font-size:12px;text-de--ation: underline;">文章分类列表</span>
                </td>
              </tr>
            </table>
          </td>
        </tr>
        <tr> 
          <td height="100" align="center" valign="top" style="padding-top:20px;padding-bottom:10px;">
            <table width="80%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
              
              <%if (!strErr.trim().equals("")) {%>
              <tr> 
                <td width="30%" height="28" align="right" bgcolor="#858585"><font color="#FFFFFF">错误提示：</font></td>
                <td bgcolor="#EDEDF0"><font color=red><%=strErr%></font>&nbsp;</td>
              </tr>
              <%}%>
              <%if (is_leaf == 1) {%>
              <tr> 
                <td width="30%" height="24" align="right" bgcolor="#858585"><font color="#FFFFFF">所属父类：</font></td>
                <td bgcolor="#D7D7DB"><%=parent_name%></td>
              </tr>
              <%}%>
              <tr> 
                <td width="30%" height="24" align="right" bgcolor="#858585"><font color="#FFFFFF">分类名称：</font></td>
                <td bgcolor="#D7D7DB"><input name="category_name" type="text" class="inputbox" value="<%=category_name%>" size="30" maxlength="50"></td>
              </tr>
              <tr>
                <td height="24" align="right" bgcolor="#858585"><font color="#FFFFFF">顺序号：</font></td>
                <td bgcolor="#EDEDF0">
                  <input name="order_id" type="text" class="inputbox" value="<%=order_id%>" size="3" maxlength="3">
                </td>
              </tr>
              <tr>
                <td height="24" align="right" bgcolor="#858585"><font color="#FFFFFF">分类描述：</font></td>
                <td bgcolor="#EDEDF0">
                  <textarea name="category_desc" cols="30" rows="5"><%=category_desc%></textarea>
                </td>
              </tr>
              <tr> 
                <td height="24" align="right" bgcolor="#EDEDF0">&nbsp;</td>
                <td bgcolor="#EDEDF0"> 
                  <input type="submit" name="submit" value="提 交" class="inputButton"> 
                  <input type="reset" name="reset" value="重 写" class="inputButton"> 
                  <input type="hidden" name="cmd" value=""> 
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
      </form>
    </td>
  </tr>
</table>
<%if (cmd.equals("insert") && strErr.trim().equals("")){%>
<script language="javascript">
try {
	parent.menuFrm.location.href = parent.menuFrm.location.href;
}
catch(ex) {
	//alert(ex.description);
}
alert("分类信息添加成功!");
location.href="know_soft_cate_list.jsp";
</script>
<%}%>
</body>
</html>